function Game(el){
    this.el = document.querySelector(el)
    //创建地图
    this.map = new Map(this.el)
    this.food = new Food(this.el)
    this.snake = new Snake(this.el)
   this.t=null
}
Game.prototype.stop = function(){
    clearInterval(this.t)
}
Game.prototype.start = function(){
    this.t=setInterval(()=>{
        this.snake.move()
        let snakex = this.snake.snakeObj[0].x * 20
        let snakey = this.snake.snakeObj[0].y * 20
        let foodx = this.food.foodx
        let foody = this.food.foodY
        if(snakex == foodx && snakey ==foody){
            // alert('11')
            let last = this.snake.snakeObj[this.snake.snakeObj.length-1]
            this.snake.snakeObj.push({
                x:last.x,
                y:last.y,
                color:last.color,
                ele:null
            })
            this.snake.init()
            this.food.suijifood()
        }
    },200)
    //吃
    

    document.addEventListener('keydown',(e)=>{
        //获取事件对象
        e = e || window.event
        switch (e.keyCode) {
            case 38:
                this.snake.direction = 'top'
            break;
            case 40:
                this.snake.direction = 'bottom'
            break;
            case 37:
                this.snake.direction = 'left'
            break;
            case 39:
                this.snake.direction = 'right'
            break;
            default:
                break;
        }
    })
}